package 一四;

import java.util.Scanner;

/**
 * Created by lenovo on 2017/3/17.
 */
public class q10 {
    public static int count =0;

    public static void lianhao(int a[]){
        for(int i=0;i<a.length;i++){
            int max = a[i];
            int min = a[i];
            for(int j =i;j<a.length;j++){
                min = Math.min(min,a[j]);
                max = Math.max(max,a[j]);
                if(max - min == j -i){
                    count ++ ;
                }
            }
        }
    }

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        scanner.nextLine();

        for(int i=0;i<n;i++){
            a[i] = scanner.nextInt();
        }
        lianhao(a);
        System.out.println(count);
    }
}
